/**
 * http接口API集中管理
 */
import config from '@/config.js'

const install = (Vue, vm) => {
	// 小程序通用的接口
	function uploadImage(filePath, params = {}) {
		return new Promise((resolve, reject) => {
			uni.uploadFile({
				url: config.HTTP_REQUEST_URL + '/bbg/upload/image',
				filePath: filePath,
				name: 'pics',
				header: {
					[config.TOKEN_NAME]: vm.$store.state.vuex_token
				},
				formData: {
					filename: 'pics',
					...params
				},
				success: (res) => {
					// console.log('upload', res.data);
					const resData = JSON.parse(res.data)
					if (resData.status == 200) {
						resolve(resData.data.url)
					} else {
						vm.$u.toast(resData.msg)
						reject()
					}
				},
				fail: (err) => {
					reject(err)
				}
			})
		})
	}

	vm.$u.api = {
		uploadImage: uploadImage,
		uploadUrl: () => (config.HTTP_REQUEST_URL + '/bbg/upload/image'),
		headerConfig: () => ({
			[config.TOKEN_NAME]: vm.$store.state.vuex_token
		}),

		wxLogin: (params) => vm.$u.get('/bbg/auth_login', params),
		wxLogOut: () => vm.$u.get('/bbg/logout'),
		wxGetUserInfo: (params = {}) => vm.$u.post('/wxGetUserInfo', params),
		wxGetPhoneNumber: (params = {}) => vm.$u.post('/bbg/auth_bindind_phone', params),
		getAppImage: (name) => config.OSS_DOMAIN + name,
		getUserInfo: () => vm.$u.get('/bbg/user/info'),
		// 注销
		cancelUser: () => vm.$u.get('/bbg/cancel/user'),
		// 版本号
		appVersion: () => vm.$u.get('/bbg/app/download'),
		// 绑定推送cid
		cidBind: (params) => vm.$u.post('/bbg/user/cid/bind', params),
		// 推送开关
		pushSet: (params) => vm.$u.post('/bbg/user/notice/set', params),
		// 获取scheme码
		mpScheme: (params) => vm.$u.get('/bbg/user/routine_scheme', params),
		// 第三方登录
		otherLogin: (key, params) => vm.$u.post(`/bbg/login/${key}`, params),
		// 第三方绑定手机号
		bindPhone: (key, params) => vm.$u.post(`/bbg/auth/${key}`, params),
		// 手机号一键登录
		oneBtnLogin: (params) => vm.$u.post(`/bbg/login/univerify`, params),
		// 验证码登录
		mobleLogin: (params) => vm.$u.post(`/bbg/login/mobile`, params),
		// 获取验证码
		getVerifyCode: (params) => vm.$u.post('/bbg/verify/code', params),
		// 修改手机号
		changePhone: (params) => vm.$u.post('/bbg/user/phone/edit', params),
		//保存资料
		saveProfile: (params = {}) => vm.$u.post('/bbg/user/power', params),
		// 上传背景图
		uploadBgImage: (params) => vm.$u.post('/bbg/user/power/bg_img', params),
		//实名认证信息
		getRealInfo: () => vm.$u.get('/bbg/user/real/info'),
		//实名认证
		userRealHandle: (params = {}) => vm.$u.post('/bbg/user/real', params),
		// 把关师申请认证
		applyPowerHandle: () => vm.$u.post('/bbg/user/power/apply'),
		// 获取海报
		shareImage: (parmas) => vm.$u.get('/bbg/user/spread_image', parmas),
		// 关注
		followHandle: (value = 0, id) => {
			let path = ''
			if (value) {
				path = '/bbg/user/follow/del'
			} else {
				path = '/bbg/user/follow/add'
			}
			return vm.$u.post(path, {
				id
			})
		},
		// 推荐列表
		agentUserList: (params) => vm.$u.get('/bbg/agent/agent_user_list', params),
		// 我看过
		visitList: (params) => vm.$u.get('/bbg/user/visit/list', params),
		// 看过我
		visit2List: (params) => vm.$u.get('/bbg/power/visit/list', params),
		// 评论点赞
		evaluateLike: (id, params) => vm.$u.post(`/bbg/serve/order/praise/${id}`, params),
		// 关注列表，被关注
		followList: (params) => vm.$u.get(`/bbg/user/follow/list`, params),
		// 发票抬头列表
		invoiceList: (params) => vm.$u.get(`/bbg/invoice`, params),
		// 新增、修改抬头
		invoiceSave: (params) => vm.$u.post(`/bbg/invoice/save`, params),
		// 删除抬头
		invoiceDelete: (id) => vm.$u.post(`/bbg/invoice/del/${id}`),
		// 获取默认抬头
		invoiceDefault: (params) => vm.$u.get(`/bbg/invoice/default`, params),
		// 抬头详情
		invoiceDetail: (id) => vm.$u.get(`/bbg/invoice/detail/${id}`),
		// 钱包明细
		walletDetail: () => vm.$u.get(`/bbg/user/money`),
		// 账单明细
		billList: (params) => vm.$u.get(`/bbg/user/money_list`, params),
		// 提现
		widthdraw: (params) => vm.$u.post('/bbg/user/extract/cash', params),
		// 开票列表
		invoiceOrderList: (params) => vm.$u.get(`/bbg/order/invoice_list`, params),
		// 推广信息
		agentInfo: () => vm.$u.get(`/bbg/agent/agent_info`),
		// 申请开票
		invoiceMake: (params) => vm.$u.post('/bbg/order/invoice_make', params),
		// 获取默认卡
		defautBank: (params) => vm.$u.get(`/bbg/bank/default`, params),
		// 设置默认 
		setBankDefaut: (id, params) => vm.$u.post(`/bbg/bank/set_default/${id}`, params),
		// 获取开户行
		bankPlace: (params) => vm.$u.get(`/bbg/bank/place`, params),
		// 卡列表
		bankList: (params) => vm.$u.get(`/bbg/bank/list`, params),
		// 添加卡
		addBankCard: (params) => vm.$u.post(`/bbg/bank/add`, params),
		// 删除卡
		delBankCard: (id) => vm.$u.post(`/bbg/bank/del/${id}`),
		/**
		 * 需求相关
		 */
		// 发布需求
		demandAdd: (params = {}) => vm.$u.post('/bbg/demand/add', params),
		// 更改需求
		demandEdit: (id, params = {}) => vm.$u.post(`/bbg/demand/edit/${id}`, params),
		// 我的需求
		userDemandList: (params = {}) => vm.$u.get('/bbg/demand/list', params),
		// 删除需求
		deleteDemand: (id) => vm.$u.post(`/bbg/demand/delete/${id}`),
		// 撤销需求
		cancelDemand: (id) => vm.$u.post(`/bbg/demand/cancel/${id}`),
		// 需求详情
		demandDetail: (id) => vm.$u.get(`/bbg/demand/detail/${id}`),
		// 需求关闭
		closeDemand: (id) => vm.$u.post(`/bbg/demand/show/${id}`),
		// 已接需求
		applyDemList: (params) => vm.$u.get(`/bbg/demand/apply/lst`, params),

		/**
		 * 服务相关
		 */
		// 发布服务
		serveAdd: (params = {}) => vm.$u.post('/bbg/serve/add', params),
		// 计算价格
		compulatePrice: (params = {}) => vm.$u.post('/bbg/serve/computed', params),
		// 更改服务
		serveEdit: (id, params = {}) => vm.$u.post(`/bbg/serve/edit/${id}`, params),
		// 服务详情
		serveDetail: (id) => vm.$u.get(`/bbg/serve/detail/${id}`),
		// 删除服务
		deleteServe: (id) => vm.$u.post(`/bbg/serve/delete/${id}`),
		// 撤销服务审核
		cancelServe: (id) => vm.$u.post(`/bbg/serve/cancel/${id}`),
		// 下架服务
		closeServe: (id) => vm.$u.post(`/bbg/serve/show/${id}`),
		// 我的服务
		userServeList: (params = {}) => vm.$u.get('/bbg/serve/list', params),

		/**
		 * 订单相关
		 */

		// 订单状态详情
		orderDetail: (id) => vm.$u.get(`/bbg/serve/apply/detail/${id}`),
		// 查询订单列表已购
		orderListBuy: (params) => vm.$u.get(`/bbg/serve/apply/lst`, params),
		// 查询订单列表已售
		orderListSold: (params) => vm.$u.get(`/bbg/serve/apply/list`, params),
		// 预约提交
		subOrderCreate: (id, params = {}) => vm.$u.post(`/bbg/serve/apply/add/${id}`, params),
		// 取消预约
		subOrderCancel: (id) => vm.$u.post(`/bbg/serve/apply/cancel/${id}`),
		// 同意预约
		subOrderAggree: (id) => vm.$u.post(`/bbg/serve/apply/agree/${id}`),
		// 拒绝预约
		subOrderRefuse: (id, params) => vm.$u.post(`/bbg/serve/apply/refuse/${id}`, params),
		// 支付
		orderPayment: (key, params) => vm.$u.post(`/bbg/serve/order/pay/${key}`, params),
		// 见面确认码
		orderMeetCode: (id, params) => vm.$u.post(`/bbg/serve/order/meet/${id}`, params),
		// 把关师交付服务
		orderComplate: (id) => vm.$u.post(`/bbg/serve/order/complete/${id}`),
		// 客户确认服务
		orderFinish: (id) => vm.$u.post(`/bbg/serve/order/finish/${id}`),
		// 评价
		evaluate: (id, params) => vm.$u.post(`/bbg/serve/order/comment/${id}`, params),
		// 用户申请退款
		applyRefund: (id, params) => vm.$u.post(`/bbg/serve/refund/${id}`, params),
		// 拒绝退款
		refuseRefund: (id) => vm.$u.post(`/bbg/serve/refund/refuse/${id}`),
		// 同意退款
		aggreeRefund: (id) => vm.$u.post(`/bbg/serve/refund/agree/${id}`),
		//  删除订单
		deleteOrder: (id) => vm.$u.post(`/bbg/serve/apply/del/${id}`),
		// 点赞评论
		evaluatePraise: (id, params) => vm.$u.post(`/bbg/serve/order/praise/${id}`, params),
		/**
		 * 接单相关
		 */
		// 申请接单
		applyOrder: (id, params) => vm.$u.post(`/bbg/demand/apply/add/${id}`, params),
		// 查询接单信息
		demOrderInfo: (id) => vm.$u.get(`/bbg/demand/apply/detail/${id}`),
		// 用户查申请信息
		demOrderInfoByUser: (id) => vm.$u.get(`/bbg/demand/apply/info/${id}`),
		// 取消申请
		cancelApplyOrder: (id) => vm.$u.post(`/bbg/demand/apply/cancel/${id}`),
		// 查询申请人
		applyerList: (params) => vm.$u.get(`/bbg/demand/apply/list`, params),
		// 同意接单
		aggreeOrder: (id) => vm.$u.post(`/bbg/demand/apply/agree/${id}`),
		// 拒绝接单
		refuseOrder: (id) => vm.$u.post(`/bbg/demand/apply/refuse/${id}`),
		// 取消订单
		cancelDemOrder: (id) => vm.$u.post(`/bbg/demand/pay/cancel/${id}`),
		// 申请退款-需求
		demandRefund: (id, params) => vm.$u.post(`/bbg/demand/refund/${id}`, params),
		// 见面确认-需求
		demandMeet: (id, params) => vm.$u.post(`/bbg/demand/order/meet/${id}`, params),
		// 交付需求
		demandComplate: (id) => vm.$u.post(`/bbg/demand/order/complete/${id}`),
		// 确认交付-需求
		demandFinish: (id) => vm.$u.post(`/bbg/demand/order/finish/${id}`),
		// 拒绝退款
		demandRefuseRefund: (id) => vm.$u.post(`/bbg/demand/refund/refuse/${id}`),
		// 同意退款
		demandAgreeRefund: (id) => vm.$u.post(`/bbg/demand/refund/agree/${id}`),
		// 把关师删除申请
		deleteApply: (id) => vm.$u.post(`/bbg/demand/apply/delete/${id}`),
		// 退款进度
		refundProgress: (id) => vm.$u.get(`/bbg/order/refund/progress/${id}`),

		/**
		 * 消息相关 
		 */
		// 消息列表
		messageList: (params) => vm.$u.get(`/bbg/chat/record_list`, params),
		messageHistory: (params) => vm.$u.get(`/bbg/chat/record`, params),
		deleteMsg: (params) => vm.$u.post(`/bbg/chat/del`, params),

		public: {
			industry_class: (params) => vm.$u.get('/bbg/industry_class', params),
			power_lst: (params = {}) => vm.$u.get('/bbg/user/power/lst', params),
			demand_lst: (params = {}) => vm.$u.get('/bbg/demand/lst', params),
			edu_list: () => vm.$u.get('/bbg/edu/lst'),
			exp_list: () => vm.$u.get('/bbg/exp/lst'),
			power_detail: (id) => vm.$u.get(`/bbg/user/power/detail/${id}`),
			appconfig: () => vm.$u.get('/bbg/config'),
			index_banner: () => vm.$u.get('/bbg/home_banner')
		}
	}
}

export default {
	install
}